package com.tarena.luban.demo.all.adapter.service.impl;

import com.tarena.luban.demo.all.adapter.mapper.CartMapper;
import com.tarena.luban.demo.all.service.ICartService;
import com.tarena.luban.commons.pojo.cart.dto.CartAddDTO;
import com.tarena.luban.commons.pojo.cart.entity.Cart;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class CartServiceImpl implements ICartService {
    @Autowired
    private CartMapper cartMapper;
    @Override
    public void cartAdd(CartAddDTO cartAddDTO) {
        Cart cart=new Cart();
        BeanUtils.copyProperties(cartAddDTO,cart);
        int row=cartMapper.insertCart(cart);
        log.info("新增购物车商品完成!{}",cart);
    }

    @Override
    public void deleteUserCart(String userId, String commodityCode) {
        cartMapper.deleteCartByUserIdAndCommodityCode(userId,commodityCode);
        log.info("购物车删除完成!");
    }
}
